package cn.teamstack.logger.enums;

import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: SshSessionVerifyEnum
 * @Description: 认SSH验证方式
 * @Author: Donaldhan
 * @Date: 2020-04-16 10:07
 */
public enum SshSessionVerifyEnum {
    /**
     * 默认password验证方式
     */
    DEFAULT("default","默认SSH验证方式，密码认证"),
    /**
     * 私钥验证方式,PRIVATE_KEY, 此方式必须私钥路径ssh.session.verify.file.path
     */
    KEYS_FILE("keysFile","SSH私钥验证");

    /**
     *
     */
    private String name;
    /**
     *
     */
    private String remark;


    SshSessionVerifyEnum(String name, String remark) {
        this.name = name;
        this.remark = remark;
    }

    /**
     * @param name
     * @return
     */
    public static SshSessionVerifyEnum getSSHSessionVerifyByName(String name){
        if(StringUtils.isEmpty(name)){
            return SshSessionVerifyEnum.DEFAULT;
        }
        List<SshSessionVerifyEnum> matchSSHSessionVerifyList =  Arrays.stream(SshSessionVerifyEnum.values())
                    .filter(e -> e.getName().equals(name)).collect(Collectors.toList());
        if(CollectionUtils.isEmpty(matchSSHSessionVerifyList)){
            return SshSessionVerifyEnum.DEFAULT;
        }
        return matchSSHSessionVerifyList.get(0);
    }

    public String getName() {
        return name;
    }


    public String getRemark() {
        return remark;
    }
}
